//
//  RefundingViewController.m
//  renmingongshe
//
//  Created by macbook on 2017/11/1.
//  Copyright © 2017年 xiaodian. All rights reserved.
//

#import "RefundingViewController.h"
#import "ConsultDetailViewController.h"
#import "RefundSuccessViewController.h"
#import "MineRefundViewController.h"

@interface RefundingViewController ()
@property (weak, nonatomic) IBOutlet UILabel *timeLb;

@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
@property (weak, nonatomic) IBOutlet UIButton *refundBtn;
@property (weak, nonatomic) IBOutlet UIButton *consultBtn;
@property (strong, nonatomic) UITableView *tableView;
@property (weak, nonatomic) IBOutlet UILabel *money;
@property (weak, nonatomic) IBOutlet UILabel *reason;
@property (weak, nonatomic) IBOutlet UILabel *time;
@end

@implementation RefundingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.titleLabel.text = @"退款";
    
    _refundBtn.layer.borderColor = [[UIColor redColor]CGColor];
    _refundBtn.layer.borderWidth = 1.0f;
    [_refundBtn.layer setCornerRadius:5.0];
    _refundBtn.layer.masksToBounds = YES;
    
    [self showInfo];
}
- (void)showInfo
{
    _money.text = [NSString stringWithFormat:@"%@元", _data[@"backMoney"]];
    _reason.text = _data[@"datas"][@"dataName"];
    _time.text = _data[@"createTime"];
    
    if ([_data[@"refundStatus"]integerValue]==-1 ) {
        //退款失败
    }else if([_data[@"refundStatus"]integerValue]==0){
        //等待处理
    }else if ([_data[@"refundStatus"]integerValue]==1)
    {
        //等待退款
    }else{
        //退款成功
    }
    [self getTime];
}

- (void)getTime
{
    NSInteger now = [[NSDate date] timeIntervalSince1970];
    NSInteger timeInt = [_data[@"strtotime"]integerValue] - now;
    
    NSInteger day = timeInt / (3600 * 24);
    timeInt -= day*24*3600;
    NSInteger hour = timeInt / 3600;
    timeInt-= hour*3600;
    NSInteger minute = timeInt / 60;
    
    
    NSString *str = [NSString stringWithFormat:@"超过0%ld天%ld时,申请达成并为您退款。",day,minute];
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc]initWithString:str];
    [attrStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(2, 2)];
    [attrStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(5, 2)];
    
    _timeLb.attributedText = attrStr;
}
- (IBAction)editRefundClick:(UIButton *)sender {
    MineRefundViewController *refund = [[MineRefundViewController alloc] init];
    refund.reasonDic = [[NSMutableDictionary alloc]initWithDictionary:_reasonDic];
    refund.moneyStr = _data[@"backMoney"];
    refund.orderId = _data[@"orderId"];
    [self.navigationController pushViewController:refund animated:YES];
    
}

- (IBAction)consultClick:(UIButton *)sender {
    ConsultDetailViewController *consult = [[ConsultDetailViewController alloc] init];
    consult.data = _data;
    [self.navigationController pushViewController:consult animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
